import { MicroServiceEnum } from '@/common/enums/httpEnum'
import { isEmpty } from '@/common/helper/is'
import $store from '@/store'

export default function getCurService(val) {
  const { ApiBaseDomain, ApiBasePrefix, ApiBaseUrl, ApiGatewayDomain, ApiGatewayPrefix, ApiGatewayUrl } = EnvScript($store.getters.DefEnvCon)

  const service = {
    base: {
      key: MicroServiceEnum.BASE,
      domain: ApiBaseDomain,
      prefix: ApiBasePrefix,
      url: ApiBaseUrl,
    },
    gateway: {
      key: MicroServiceEnum.GATEWAY,
      domain: ApiGatewayDomain,
      prefix: ApiGatewayPrefix,
      url: ApiGatewayUrl,
    },
  }

  if (isEmpty(val)) return service.base

  const serviceObj = Object.values(service).find((item) => item.key === val) || service.base

  return serviceObj
}
